<#import "../layout.ftl" as layout>

<#macro loginPage title="">
<!DOCTYPE html>
<html style="height: 100%;"  style=" background-image: linear-gradient(to right, #381267 , #d00557);">

<head >
    <script>
        if(self != top){
            top.location.href="/wechat/admin";
        }
    </script>
    <meta charset="UTF-8">
    <!-- 初始化移动浏览显示 -->
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <!-- 在IE运行最新的渲染模式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta http-equiv="X-UA-Compatible" content="IE=9"/>

    <#if title=="">
        <title>${systemName}</title>
    <#else>
        <title>${title}</title>
    </#if>

    <!-- bootstrap -->
    <link rel="stylesheet" type="text/css" href="${request.contextPath}/assets/bootstrap/css/bootstrap.min.css?v=3553060703">
    <!-- font-awesome 字体 -->
    <link rel="stylesheet" type="text/css" href="${request.contextPath}/assets/fonts-awesome/css/font-awesome.min.css?v=3553060703">
    <!-- 弹窗 -->
    <link rel="stylesheet" type="text/css" href="${request.contextPath}/assets/sweetalert2/sweetalert2.min.css?v=3653060703">

    <link rel="stylesheet" type="text/css" href="${request.contextPath}/assets/alone/css/login.css?v=3553060703">
    <link rel="stylesheet" type="text/css" href="${request.contextPath}/assets/select2/select2.min.css?v=3653060703">

</head>

<body id="login-page" style="height: 100%;" >
<div style="height: 100%; background-image: linear-gradient(to right, #381267 , #d00557);">

    <div style="height: 100%;
            background: url('${request.contextPath}/assets/user/images/${systemBgAdmin}') no-repeat top center;
            background-size:cover; ">
<div style="    background-color: rgba(104, 180, 197, 0.39);width:100%;height:250px; position: absolute;top:calc(50% - 200px) ;left:0px;"></div>
        <div id="login-box">
            <div class="row">
                <div class="col-xs-12">
                    <header id="login-header">
                        <div id="login-logo">
                            <img src="${request.contextPath}/assets/user/images/${systemIcon}">
                            <span>${systemName}</span>
                        </div>
                    </header>
                    <div id="login-box-inner">
                        <form role="form">
                            <div class="input-group">
                                <span class="input-group-addon">
                                    <i class="fa fa-user"></i>
                                </span>
                                <input id="txtName" class="form-control" type="text" name="username"
                                       placeholder="请输入登录用户名">
                            </div>
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-key"></i></span>
                                <input id="txtPwd" type="password" class="form-control" name="password"
                                       placeholder="请输入登录密码">
                            </div>
                            <div class="input-group" style="display: none;">
                                <span class="input-group-addon"><i class="fa fa-hand-o-right"></i></span>
                                <select id="systemid" name="cSystemID" class="form-control" placeholder="请选择系统">
                                </select>
                            </div>
                            <#--<div class="input-group">-->
                                <#--<span class="input-group-addon"><i class="fa fa-info-circle"></i></span>-->
                                <#--<a id="labVersion"></a>&nbsp;&nbsp;<a id="labRegister"><u>未注册</u></a>-->
                            <#--&lt;#&ndash;<input id="txtVersion" type="text" class="form-control" readonly>&ndash;&gt;-->
                            <#--</div>-->
                        <#--<div id="remember-me-wrapper">-->
                        <#--<div class="row">-->
                        <#--<div class="col-xs-6">-->
                        <#--<div class="checkbox-nice">-->
                        <#--<input type="checkbox" id="remember-me" name="rememberMe"/>-->
                        <#--<label for="remember-me">-->
                        <#--记住我-->
                        <#--</label>-->
                        <#--</div>-->
                        <#--</div>-->
                        <#--</div>-->
                        <#--</div>-->
                            <div class="row">
                                <div class="col-xs-12">
                                    <button id="btnLogin" class="btn btn-primary col-xs-12" style="background-color: #031fc9" data-loading-text="正在登录...">
                                        登&nbsp;&nbsp;&nbsp;&nbsp;录
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <footer id="footer-bar">
        <p id="footer-copyright">
        ${systemComName}
        </p>
    </footer>
</div>

<!-- jquery -->
<script type="text/javascript" src="${request.contextPath}/assets/js/jquery-1.12.4.min.js?v=3653060703"></script>


<link rel="stylesheet" href="${request.contextPath}/assets/weUI/lib/weui.min.css?v=3753060703">
<link rel="stylesheet" href="${request.contextPath}/assets/weUI/css/jquery-weui.css?v=3653060703">
<script src="${request.contextPath}/assets/weUI/js/jquery-weui.js?v=3653060703"></script>
<!-- bootstrap -->
<script type="text/javascript" src="${request.contextPath}/assets/bootstrap/js/bootstrap.min.js?v=3553060703"></script>
<!-- 弹窗 -->
<script type="text/javascript" src="${request.contextPath}/assets/sweetalert2/sweetalert2.all.min.js?v=3653060703"></script>
<!-- select2 -->
<script type="text/javascript" src="${request.contextPath}/assets/select2/select2.full.min.js?v=3653060703"></script>
<script type="text/javascript" src="${request.contextPath}/assets/select2/i18n/zh-CN.js?v=3653060703"></script>

<script type="text/javascript">
    var contextPath = "${request.contextPath}";
    window.onload = function () {
        $("#txtName").blur();
        $('#systemid').select2({
            language: "zh-CN",
            minimumResultsForSearch: -1
        });

        var version = '${version}';
        version = version.substr(0, version.indexOf("/n"));
        $("#labVersion").html(version);

    <#--var bRegister = ${vcMap['bRegister']};-->
    <#--if (bRegister)-->
    <#--$("#labRegister").show();-->

    };

    $("#labVersion").click(function () {
        var version = '${version}';
        layer.open({
            title: '版本信息',
            formType: 2,
            area: ['500px', '400px'],
            btn: ['确定'],
            content: version.replace(/\/n/g, "<br/>")
        });
    });

    $("#labRegister").click(function () {
        var xlh = '${vcMap['xlh']}';
        var version = '${version}';
        version = version.substr(0, version.indexOf("/n"));
        layer.prompt({
            title: '版本注册！',
            formType: 2,
            area: ['500px'],
            closeBtn: 0,
            btn: ['下一步', '关闭'],
            value: '当前版本尚未注册，请联系产品负责人索取注册码！\n' + version + '\n序列号：' + xlh,
        }, function (wb, index) {
            layer.close(index);
            layer.prompt({
                title: '请输入注册码',
                formType: 2,
                area: ['500px'],
                closeBtn: 0,
                btn: ['注册', '关闭']
            }, function (zcm, index) {
                layer.close(index);

                $.ajax({
                    type: 'POST',
                    data: 'xlh=' + xlh + '&zcm=' + zcm,
                    url: contextPath + '/register',
                    success: function (data) {
                        if (data.success) {
                            if (data.data == 1) {
                                layer.msg('注册成功！<br>序列号：' + xlh + '<br>注册码：' + zcm);
                                setTimeout(function () {
                                    location.href = "${request.contextPath}/";
                                }, 1000);
                            } else {
                                layer.msg('注册失败！', {anim: 6});
                            }
                        }
                        else {
                            swal("错误", data.errorMsg, "error");
                        }
                    }
                });
            });
        });
    });

    $("#btnLogin").click(function (e) {
    <#--var bRegister = ${vcMap['bRegister']};-->
    <#--if (bRegister) {-->
    <#--swal("错误", "系统还未注册!", "error");-->
    <#--return;-->
    <#--}-->

        e.preventDefault();
        var $btn = $(this);
        $(this).button('loading');
        var username = $("#txtName").val();
        if (username == null || username == "") {
            swal("错误", "登录用户名不能为空!", "error");
            $btn.button('reset');
            return;
        }
        var password = $("#txtPwd").val();
        if (password == null || password == "") {
            swal("错误", "登录密码不能为空!", "error");
            $btn.button('reset');
            return;
        }
        var systemid= $("#systemid").val();
        if (systemid == null || systemid == "") {
            swal("错误", "此用户不存在!", "error");
            $btn.button('reset');
            return;
        }
        var requestData = $("form").serialize();
        $.ajax({
            type: 'POST',
            data: requestData,
            url: contextPath + '/login/verify',
            success: function (data) {
                if (data.success) {
                    location.href = "${request.contextPath}/";
                }
                else {
                    swal("登录失败", data.errorMsg, "error");
                }
                $btn.button('reset');
            },
            failure: function () {
                swal("登录失败", "发生未知错误", "error");
                $btn.button('reset');
            }
        });

    });
    $("#txtName").blur(function () {
        $.showLoading("处理中...");
        $.ajax({
            type: 'POST',
            data: {datas: "{\"userCode\":\"" + $("#txtName").val() + "\"}"},
            url: contextPath + '/login/getsystemlist',
            success: function (datas) {
                $.hideLoading();
                $("#systemid").empty();
                var data = datas.datas;
                if (data.length > 0) {
                    $.each(data, function (n, value) {
                        $("#systemid").append("<option value='" + value["cSystemID"] + "'>" + value["cSystemName"] + "</option>");
                    });
                    $("#systemid").val(data[0]["cSystemID"]);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.hideLoading();
                swal("错误", "系统发生内部错误!请稍后再试!", "error");
            }
        });
    });
</script>

</body>
</html>
</#macro>